package com.jy.oms.framework.asyn.task.core;


import com.jy.oms.framework.asyn.job.StandaloneJobConfig;

import java.util.List;

/**
 * task配置
 *
 * @author liuquan
 */
public class ExecutorConfig {

    /**
     * 是否允许当前服务器执行task
     */
    private boolean enableTaskExecutor;

    /**
     * 当前服务标识
     */
    private String businessGroup;

    /**
     * 任务框架里用到redis的地方，key的前缀
     * 异步任务框架里用到redis地方，key以【缓存前缀:业务组标识，即BusinessGroupRedisPrefix:BusinessGroup】开头
     * 默认为asyn-task，为防止出现相同的businessGroup，可以自定义前缀
     */
    private String businessGroupRedisPrefix;

    /**
     * 环境标识，通过ServerConfigAdapter来适配
     * boot框架，默认为ConfUtil.getEnv()
     * S11框架，默认为DisConfUtil.getDisConfEnv
     */
    private String env;

    /**
     * RedissonClient spring bean名称
     */
    private String redissonClientBean = "redissonClient";

    /**
     * 默认同businessGroup, 便于验证提交任务|执行任务 应用配置是否合法
     */
    private String sign;

    /**
     * 是否可告警； 默认只有生产环境可以告警（企信告警）
     */
    private Boolean ableAlarm;

    /**
     * 是否开启集群模式，集群模式下，可充分利用闲置机器，加快任务执行速率； 默认只有一个节点会执行任务
     */
    private boolean enableCluster;

    /**
     * 默认运行redis队列任务可运行在多节点集群模式
     */
    private boolean enableRedisTaskRunInClusterMode = true;

    /**
     * 单机版任务配置
     */
    private StandaloneJobConfig standaloneJobConfig;

    /**
     * 业务异常，log不输出error异常栈，也不告警
     */
    private List<Class<? extends Throwable>> businessExceptions;

    /**
     * task容错配置
     */
    private ExecutorFailoverConfig executorFailoverConfig;

    public boolean isEnableTaskExecutor() {
        return enableTaskExecutor;
    }

    public ExecutorConfig setEnableTaskExecutor(boolean enableTaskExecutor) {
        this.enableTaskExecutor = enableTaskExecutor;
        return this;
    }

    public String getBusinessGroup() {
        return businessGroup;
    }

    public ExecutorConfig setBusinessGroup(String businessGroup) {
        this.businessGroup = businessGroup;
        return this;
    }

    public String getEnv() {
        return env;
    }

    public ExecutorConfig setEnv(String env) {
        this.env = env;
        return this;
    }

    public String getBusinessGroupRedisPrefix() {
        return businessGroupRedisPrefix;
    }

    public ExecutorConfig setBusinessGroupRedisPrefix(String businessGroupRedisPrefix) {
        this.businessGroupRedisPrefix = businessGroupRedisPrefix;
        return this;
    }

    public String getSign() {
        return sign;
    }

    public ExecutorConfig setSign(String sign) {
        this.sign = sign;
        return this;
    }

    public Boolean getAbleAlarm() {
        return ableAlarm;
    }

    public ExecutorConfig setAbleAlarm(Boolean ableAlarm) {
        this.ableAlarm = ableAlarm;
        return this;
    }

    public boolean isEnableCluster() {
        return enableCluster;
    }

    public ExecutorConfig setEnableCluster(boolean enableCluster) {
        this.enableCluster = enableCluster;
        return this;
    }

    public String getRedissonClientBean() {
        return redissonClientBean;
    }

    public ExecutorConfig setRedissonClientBean(String redissonClientBean) {
        this.redissonClientBean = redissonClientBean;
        return this;
    }

    public StandaloneJobConfig getStandaloneJobConfig() {
        return standaloneJobConfig;
    }

    public ExecutorConfig setStandaloneJobConfig(StandaloneJobConfig standaloneJobConfig) {
        this.standaloneJobConfig = standaloneJobConfig;
        return this;
    }

    public List<Class<? extends Throwable>> getBusinessExceptions() {
        return businessExceptions;
    }

    public ExecutorConfig setBusinessExceptions(List<Class<? extends Throwable>> businessExceptions) {
        this.businessExceptions = businessExceptions;
        return this;
    }

    public ExecutorFailoverConfig getExecutorFailoverConfig() {
        return executorFailoverConfig;
    }

    public boolean isEnableRedisTaskRunInClusterMode() {
        return enableRedisTaskRunInClusterMode;
    }

    public ExecutorConfig setEnableRedisTaskRunInClusterMode(boolean enableRedisTaskRunInClusterMode) {
        this.enableRedisTaskRunInClusterMode = enableRedisTaskRunInClusterMode;
        return this;
    }

    public ExecutorConfig setExecutorFailoverConfig(ExecutorFailoverConfig executorFailoverConfig) {
        this.executorFailoverConfig = executorFailoverConfig;
        return this;
    }
}
